package com.colin.aiyi.ui.personal;

import com.colin.aiyi.app.MyApp;
import com.colin.aiyi.dao.ImpxUtils.ImpSaveUserInfo;
import com.colin.aiyi.dao.ImpxUtils.ImpUploadImg;
import com.colin.aiyi.entity.response.BaseResponse;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.presenter.AbsP;
import com.colin.aiyi.utils.SharePreferenceUtil;

/**
 * Created by hl on 2017/6/14.
 */

public class ImpPPersonal extends AbsP {
    private long exitTime;
    private User user;

    @Override
    public void onSuccess(Object t) {
        super.onSuccess(t);
        BaseResponse baseResponse= (BaseResponse) t;
        if (baseResponse.getCode()==200){
            if((System.currentTimeMillis()-exitTime) > 2000){
                exitTime = System.currentTimeMillis();
                if (user.getHeadUrl_local()==null){
                    SharePreferenceUtil.saveObject(MyApp.getInstance().getApplicationContext(),user);
                    sendMsgToView(user);
                    sendMsgToView(baseResponse);
                    return;
                }
                uploadImg(user);
            }
        }else {
            sendMsgToView(t);
        }

    }

    @Override
    public <V> void user_saveUserInfo(V v) {
        super.user_saveUserInfo(v);
        user= (User) v;
        iService=new ImpSaveUserInfo();
        iService.getObject(this,v);
//        uploadImg(v);
    }

    private  <V>  void uploadImg(V v){
        iService=new ImpUploadImg();
        iService.getObject(v);

    }






}
